package com.zlsy.secondtime.singleton;

import com.zlsy.thread.singleton.Test;
import com.zlsy.thread.singleton.Test1;
import com.zlsy.thread.singleton.Test2;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zhouliang
 * @date 2020/6/13 9:35
 * 单例模式之 最好的模式：枚举
 */
public enum Singleton7 {
    /**
     * 这个实例对象
     */
    INSTANCE;

    private Map<String, Test> map = new HashMap<>();

    Singleton7() {
        Test test1 = new Test1();
        Test test2 = new Test2();
        map.put("a", test1);
        map.put("b", test2);
        //枚举单例注释。。
    }

    public Test get(String key) {
        return map.get(key);
    }
}
